from nevow import inevow


def moderatedListings(objects, request):
    """
    filter out any unmoderated listings from a list
    of Event objects (context is a Twisted context)
    """

    mind = request.session.mind

    rtn = []
    removed = 0
    for obj in objects:
        if obj.isApproved():
            rtn.append(obj)

        elif mind.canModerate(obj):
            rtn.append(obj)

        else:
            removed = removed + 1
    return (removed,rtn)
